package linking;

import java.util.ArrayList;
import java.util.List;

import tools.EntityRetriever;
import tools.LuceneNameRetriever;
import tools.QueryParser;
import tools.ResultOutput;

import entities.Entity;
import entities.Query;
import entities.Result;

// just use lucne index to find all the possible names, assignning 0 to each entity
public class NaiveLinking extends	Linking{
	
	private EntityRetriever er;
	
	public NaiveLinking(EntityRetriever er){
		this.er = er;
	}

	@Override
	public ArrayList<Entity> linking(Query query) {
		// TODO Auto-generated method stub
		ArrayList<Entity> list = this.er.getEntities(query.getName());
		return list;
	}

	public EntityRetriever getEr() {
		return er;
	}

	public void setEr(EntityRetriever er) {
		this.er = er;
	}
	
	public static void main(String[] args) throws Exception{
	     QueryParser qp = new QueryParser("/largedata1/cmput696/students/lyao1/data/dev.xml");
	     EntityRetriever er = new LuceneNameRetriever("/largedata1/cmput696/luceneIndex/lucene-a2e");
	     ArrayList<Result> rl = new ArrayList<Result>();
	     Linking  lk = new NaiveLinking(er);
	     List<Query> qs = qp.getQueries();
	     
	     //int limit =2;
	     //int i=0;
	     for( Query q: qs){
	    	 ArrayList<Entity> es = lk.linking(q);
	    	 System.out.println("query:"+q.getName()+" size:"+es.size());
	    	 Result r = new Result(q,es);
	    	 rl.add(r);
	    	// i++;
	    	// if( i>limit ){
	    	//	 break;
	    	 //}
	    	 
	     }
	     
	     ResultOutput rop = new ResultOutput("/largedata1/cmput696/students/lyao1/data/result.xml",qp.getQueryPath(),rl);
	     rop.output();
	}
	

}
